/*
 *  Copyright 2012 yura.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.odg.m_ui.util;

import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 *
 * @author yura
 */
public class LinkedHashtable<K, V> extends Hashtable<K, V>{

    private static final long serialVersionUID = 3801124242820219131L;

    private LinkedHashMap hashMap = new LinkedHashMap();

    @Override
    public boolean contains(Object value) {
        return hashMap.containsValue(value);
    }

    @Override
    public boolean containsKey(Object key) {
        return hashMap.containsKey(key);
    }

    @Override
    public Set<Entry<K, V>> entrySet() {
        return hashMap.entrySet();
    }

    @Override
    public boolean isEmpty() {
        return hashMap.isEmpty();
    }

    @Override
    public Set<K> keySet() {
        return hashMap.keySet();
    }

    @Override
    public Enumeration<K> keys() {
        return new Enumeration<K>() {

            Iterator<K> iterator = keySet().iterator();

            public boolean hasMoreElements() {
                return iterator.hasNext();
            }

            public K nextElement() {
                return iterator.next();
            }
        };
    }

    @Override
    public V put(K key, V value) {
        return (V) hashMap.put(key, value);
    }

    @Override
    public void putAll(Map<? extends K, ? extends V> t) {
        hashMap.putAll(t);
    }

    @Override
    public int size() {
        return hashMap.size();
    }

    @Override
    public Collection<V> values() {
        return hashMap.values();
    }

    @Override
    public String toString() {
        return hashMap.toString();
    }

    @Override
    public Enumeration<V> elements() {
        return new Enumeration<V>() {

            Iterator<V> iterator = values().iterator();

            public boolean hasMoreElements() {
                return iterator.hasNext();
            }

            public V nextElement() {
                return iterator.next();
            }
        };
    }

    @Override
    protected void rehash() {
        throw new IllegalArgumentException("Not support");
    }

    @Override
    public V remove(Object key) {
        return (V) hashMap.remove(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return hashMap.containsValue(value);
    }

    @Override
    public V get(Object key) {
        return (V) hashMap.get(key);
    }

    @Override
    public void clear() {
        hashMap.clear();
    }

}
